<template>

	<view class="body">

		<view class="input_box">
			<van-cell-group>
				<van-field :value="form.school" @input="getSchoolValue" clearable label="学院" required/>
			</van-cell-group>
			<view class="uni-form-item uni-column label">
				<picker @change="bindPickerChange2" :range="array2" :value="index2">
					<van-cell title="年级" class="picker" :value="array2[form.index2]" is-link required/>
				</picker>
				<!-- <view>{{array[index]}}</view> -->
			</view>
			<van-cell-group>
				<van-field :value="form.major" @input="getMajorValue" clearable label="专业" />
			</van-cell-group>
		</view>

		<view class="input_box">
			<van-cell-group>
				<van-field :value="form.phoneNumber" @input="getPhoneNumberValue" clearable label="电话" />
				<van-field :value="form.weChatNumber" @input="getWeChatNumberValue" clearable label="微信" required/>
				<van-field :value="form.QQ" @input="getQQValue" clearable label="QQ" />
				<van-field :value="form.email" @input="getEmailValue" clearable label="email" />
			</van-cell-group>
		</view>

		<view class="input_box">
			<van-cell-group>
				<van-field :value="form.exPosition" @input="getExPositionValue" clearable label="期望职位" />
			</van-cell-group>
			<view class="uni-form-item uni-column label">
				<picker header-text="城市选择" @change="bindPickerChange" :range="array">
					<!-- <label class="input_label">期望城市</label>
					<image class="xialaimage" src="../../static/xiala.png"
						style="margin-top: 16rpx;left:6rpx;margin-right:24rpx;width:18rpx;height:18rpx;"></image>
					<label class="pick">{{array[index]}}</label> -->
					<van-cell title="期望城市" class="picker" :value="array[form.index]" is-link />
				</picker>
				<!-- <view>{{array[index]}}</view> -->
			</view>
			<van-cell-group>
				<van-field :value="form.exCompany" @input="getExCompanyValue" clearable label="期望企业" />
			</van-cell-group>
		</view>

		<button @click="editInfo" class="submit" type="primary">提交</button>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				array:['北京','西安','南京','上海','武汉','深圳','广州','成都',
				'重庆','杭州','天津'],
				array2:['大一','大二','大三','大四','研一','研二','研三','博士'],
				form:{
					"school": "",
					"major": "",
					"grade": 0,
					"phoneNumber": "",
					"weChatNumber": "",
					"QQ": "",
					"email": "",
					"exCityId":0,
					"exPosition":"",
					"exCompany": "",
					"index": 1,
					"index2": 5
				}
			}
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e)//改变的事件名
				this.form.index = e.target.value			//将数组改变索引赋给定义的index变量
				this.form.exCityId=this.form.index
			},
			bindPickerChange2: function(e) {
				console.log('picker发送选择改变，携带值为', e)//改变的事件名
				this.form.index2 = e.target.value			//将数组改变索引赋给定义的index变量
				this.form.grade=this.form.index2
			},
			getSchoolValue(e){
				// console.log(e)
				this.form.school = e.detail
			},
			getMajorValue(e){
				//console.log(e)
				this.form.major = e.detail
			},
			getPhoneNumberValue(e){
				//console.log(e)
				this.form.phoneNumber = e.detail
			},
			getWeChatNumberValue(e){
				//console.log(e)
				this.form.weChatNumber = e.detail
			},
			getQQValue(e){
				//console.log(e)
				this.form.QQ = e.detail
			},
			getEmailValue(e){
				//console.log(e)
				this.form.email = e.detail
			},
			getExPositionValue(e){
				//console.log(e)
				this.form.exPosition = e.detail
			},
			getExCompanyValue(e){
				//console.log(e)
				this.form.exCompany = e.detail
			},
			editInfo(){
				console.log(uni.getStorageSync("userInfo"))
				uni.request({
					header: {
						'Content-Type': 'application/json'  
					}, 
					url:'https://hotenergy.club/workapp/user/Init_info', 
					method: 'POST',
					data: {
						userId: uni.getStorageSync("userInfo").userId,
						school:this.form.school,
						major:this.form.major,		
						exCityId:this.form.exCityId,	
						exPosition:this.form.exPosition,
						grade: this.form.grade,
						phoneNumber: this.form.phoneNumber,
						weChatNumber: this.form.weChatNumber,
						QQ: this.form.QQ,
						email: this.form.email,
						exCompany: this.form.exCompany,
						// school:"西电",
						// qualification:"硕士",	
						// major:"通信工程",	
						// graduationDate:"2021-06-06",	
						// exCityId:"1",	
						// exPosition:"Java开发"
						},
					success: (res) => {
						console.log(res);
						var userInfo = uni.getStorageSync('userInfo');
						userInfo.school=this.form.school;
						userInfo.major=this.form.major;
						userInfo.exCityId=this.form.exCityId;
						userInfo.exPosition=this.form.exPosition;
						userInfo.grade=this.form.grade;
						userInfo.phoneNumber=this.form.phoneNumber;
						userInfo.weChatNumber=this.form.weChatNumber;
						userInfo.QQ=this.form.QQ;
						userInfo.email=this.form.email;
						userInfo.exCompany=this.form.exCompany;
						uni.setStorageSync('userInfo',userInfo);

						console.log(uni.getStorageSync("userInfo"));
						uni.showToast({
							title:"编辑信息成功！",
						})
						// this.form={"content":"","connect":"",}
					} 
				})
				console.log(this.form)
			},
		}
	}
</script>

<style>
page {
		background: #ededed;
		margin: 1vh 0;
	}
	.van-cell {
		height: 8.5vh;
		line-height: 8.5vh;
		
	}
	.van-field__input {
		text-align: right !important;
	}
	.uni-form-item {
		height: 8.5vh;
		line-height: 8.5vh;
	}
	.input_box {
		margin-bottom: 1.5vh;
		
	}
	.submit {
		width: 400rpx;
		background-color: #666FFC !important;
	}

</style>
